package com.ruoyi.web.controller.material.mapper;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.web.controller.material.entity.YlProduct;
import com.ruoyi.web.controller.material.entity.request.ItemRequest;
import com.ruoyi.web.controller.material.entity.ylProductCategory;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;

/**
 * 物资Mapper接口
 *
 * @author jzx
 * @date 2025-10-21
 */
@Mapper
public interface YlProductMapper extends BaseMapper<YlProduct> {
    /**
     * 物资列表查询
     *
     * @param itemRequest
     * @return
     */
    default List<YlProduct> getPage(ItemRequest itemRequest) {
        LambdaQueryWrapper<YlProduct> queryWrapper = new LambdaQueryWrapper<>();
        if (StringUtils.isNotEmpty(itemRequest.getProductName())) {
            queryWrapper.like(YlProduct::getProductName, itemRequest.getProductName());
        }
        if (StringUtils.isNotEmpty(itemRequest.getUseStatus())) {
            queryWrapper.eq(YlProduct::getUseStatus, itemRequest.getUseStatus());
        }
        return selectList(queryWrapper);
    }

    /**
     * 判断名称是不是存在
     *
     * @param productName
     * @param id
     * @return
     */
    default boolean getProductName(String productName, String id) {
        if (StringUtils.isNotEmpty(id)) {
            return selectCount(new LambdaQueryWrapper<YlProduct>().eq(YlProduct::getProductName, productName).ne(YlProduct::getId, id)) > 0;
        }
        return selectCount(new LambdaQueryWrapper<YlProduct>().eq(YlProduct::getProductName, productName)) > 0;

    }

    ;;
}
